package com.ydles.system.filter;


import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * 危险操作记录日志打印
 *
 */
@Component
public class UrlFilter implements Ordered, GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        //拿到请求和响应，不就可以为所欲为了
        ServerHttpRequest request = exchange.getRequest();
        ServerHttpResponse response = exchange.getResponse();

        URI uri = request.getURI();
        String path = uri.getPath();//拿到path路径

        if (path.contains("admin/delete")){
            //logger.info  记录日志

        }
        return chain.filter(exchange);
    }

    //返回值越小越先执行
    @Override
    public int getOrder() {
        return 0;
    }
}
